package com.deductive.web.disposition.wq;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.deductive.common.core.controller.BaseController;
import com.deductive.common.core.domain.AjaxResult;
import com.deductive.common.core.page.TableDataInfo;
import com.deductive.common.utils.DateUtils;
import com.deductive.domain.wq.DispositionWqZchjhdldxcj;
import com.deductive.service.wq.DispositionWqZchjhdldxcjService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 战场环境和地理地形场景类.
 *
 * @author yexiaolong
 * @version 1.0
 * @since 2025/8/29
 */
@RestController
@RequestMapping("/battlefieldGeographicalScenario")
@Api(tags = "WQ-战场环境和地理地形场景管理")
public class BattlefieldGeographicalScenarioController extends BaseController {

    @Resource
    private DispositionWqZchjhdldxcjService dispositionWqZchjhdldxcjService;

    @GetMapping("/list")
    @ApiOperation("战场环境和地理地形场景列表")
    public TableDataInfo list(DispositionWqZchjhdldxcj data) {
        startPage();
        LambdaQueryWrapper<DispositionWqZchjhdldxcj> eq = new LambdaQueryWrapper<>();
        eq.like(StringUtils.isNotBlank(data.getProjectName()),DispositionWqZchjhdldxcj::getProjectName,data.getProjectName());
        List<DispositionWqZchjhdldxcj> list = dispositionWqZchjhdldxcjService.list(eq);
        return getDataTable(list);
    }

    @PutMapping("/update")
    @ApiOperation("战场环境和地理地形场景修改")
    public AjaxResult update(@RequestBody DispositionWqZchjhdldxcj data) {
        try
        {
            data.setUpdateTime(DateUtils.getNowDate());
            return AjaxResult.success(dispositionWqZchjhdldxcjService.updateById(data));
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage(),false);
        }
    }

    @PostMapping("/insert")
    @ApiOperation("战场环境和地理地形场景新增")
    public AjaxResult insert(@RequestBody DispositionWqZchjhdldxcj data) {
        try
        {
            data.setCreateTime(DateUtils.getNowDate());
            return AjaxResult.success(dispositionWqZchjhdldxcjService.save(data));
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage(),false);
        }
    }

    @DeleteMapping
    @ApiOperation("战场环境和地理地形场景删除")
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return AjaxResult.success(dispositionWqZchjhdldxcjService.removeByIds(idList));
    }
}
